package cn.com.haopy.dataes.db.service.main.impl;

import cn.com.haopy.dataes.db.mapper.main.HDLogMapper;
import cn.com.haopy.dataes.db.service.main.HDLogService;
import cn.com.haopy.dataes.db.entity.main.HDLog;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class HDLogServiceImpl extends ServiceImpl<HDLogMapper, HDLog> implements HDLogService {
    @Override
    public Page<HDLog> querySelective(String adminName, Integer pageNo, Integer size, String sort, String order) {
        QueryWrapper<HDLog> queryWrapper = new QueryWrapper<>();

        if (StringUtils.hasText(adminName)) {
            queryWrapper.lambda().eq(HDLog::getAdmin, adminName);
        }

        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }

        Page<HDLog> page = new Page<>(pageNo, size);

        return super.page(page, queryWrapper);
    }
}
